import json

from unit.models.dimensionModel import BasicDimension
from unit.utils.unitUtils import unit_log
from unit.serializers.dimension.basicDimensionInfoSerializer import BasicDimensionLogSereializer


def init_basic_dimension(file_name):
    with open(file_name, 'r', encoding="utf-8") as f:
        data = json.load(f)
    basic_dimension_list = []
    for basic_dimension_data in data:
        user_name = "admin"
        basic_dimension_data["create_person"] = user_name
        basic_dimension_data["modify_person"] = user_name
        basic_dimension = BasicDimension(**basic_dimension_data)
        basic_dimension_list.append(basic_dimension)
    basic_dimension_list = BasicDimension.objects.bulk_create(
        basic_dimension_list)
    # unit_log(log_person=user_name, log_type="add", log_objects=[BasicDimensionLogSereializer(basic_dimension).data for basic_dimension in basic_dimension_list
    #                                                             ], log_contents=None, log_comment="数据初始化")
